package pres.dnf.test.java.springcloud.service.ops1.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dengfan
 * @version 1.0
 * @description
 * @date 2018/9/11 0011 14:44
 */
@RestController
@Api(value = "基本运算",description = "运行基本运算")
public class OpsAPI {

    private final Logger logger = LoggerFactory.getLogger(OpsAPI.class);

    @Autowired
    private DiscoveryClient client;

    @RequestMapping(value = "/add")
    @ApiOperation(value = "加法运算",notes = "运算两个数相加")
    public Integer add(@RequestParam Integer a, @RequestParam Integer b){
        ServiceInstance serviceInstance = client.getLocalServiceInstance();
        Integer r = a + b;
        logger.info("/add,  host:" + serviceInstance.getHost() + ", service_id:" + serviceInstance.getServiceId() + ", result:" + r);
        return r;
    }
}
